package com.thread.collection;

import java.util.Vector;
import java.util.concurrent.TimeUnit;

public class Ticket_Vector_sell_more_question {

    static Vector<String> tickets = new Vector<>();
    static{
        for(int i=0;i<1000;i++)tickets.add("ticket"+i);
    }

    public static void main(String[] args) {
        for(int i=0;i<1000;i++){
            new Thread(()->{
                while(tickets.size()>0){//虽然这里枷锁了，但是下面线程睡眠，让出cput依然会存在超卖

                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();

                    }

                    System.out.println("get "+tickets.remove(0));
                }
            }).start();
        }
    }
}
